<template>
	<view class="page">
		<view class="u-flex user-box u-p-l-40 u-p-t-20 u-p-r-30 u-p-b-40">
			<view class="u-m-r-30">
				<u-avatar :src="pic" size="130" mode="square"></u-avatar>
			</view>
			<view class="u-flex-1">
				<view class="u-font-18 u-p-b-20">{{userInfo.userName}}</view>
				<view class="u-font-14 u-p-b-16 u-tips-color">帐号：{{userInfo.loginName}}</view>
			</view>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="coupon" title="我的资料" @click="toCenter()"></u-cell-item>
				<u-cell-item icon="lock" title="修改密码" @click="toPassword()"></u-cell-item>
				<u-cell-item icon="email" title="消息中心" @click="toMessage()"></u-cell-item>
				<u-cell-item icon="question-circle" title="关于系统" @click="toMessage()"></u-cell-item>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="setting" title="退出登录" @click="logout()"></u-cell-item>
			</u-cell-group>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					userName: '未登录',
					loginName: 'xxxxxx'
				},
				pic: '/static/image/avatar.jpg'
			}
		},
		onLoad() {
			this.loadUserInfo()
		},
		methods: {
			loadUserInfo() {
				this.$u.api.getUserInfo().then( res => {
					this.userInfo.userName = res.data.userName
					this.userInfo.loginName = res.data.loginName
				})
			},
			toCenter() {
				uni.navigateTo({
					url: '../my/userInfo'
				});
			},
			toPassword() {
				uni.navigateTo({
					url: '../my/password'
				});
			},
			toMessage() {
				this.$dm.showMessage("无内容")
			},
			logout() {
				uni.removeStorageSync('token')
				this.$dm.showSuccess('退出成功')
				setTimeout(() => {
					uni.reLaunch({
						url: '../my/login'
					});
				}, 1000)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.user-box {
		background-color: #fff;
	}
</style>
